<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="icon iconfont icon-jifen"></i>评价管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                类型：
                <el-select v-model="value" placeholder="请选择" style="width:120px">
                    <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
                <span style="padding-left:20px;"></span>
                【项目|门店|商品】名称：
                <el-input v-model="title" placeholder="请输入标题" class="handle-input"></el-input>
                用户昵称：
                <el-input v-model="nickName" placeholder="请输入用户昵称" class="handle-input"></el-input>
                用户手机号码：
                <el-input v-model="mobile" placeholder="请输入用户手机号码" class="handle-input"></el-input>
                <el-button type="primary" icon="search" @click="search">查询</el-button>
            </div>
            <el-table :data="tableData" border style="width: 100%" >
                <el-table-column prop="id" label="ID" width="80" align="center">
                </el-table-column>
                <el-table-column prop="nick_name" label="用户昵称" width="150">
                </el-table-column>
                <el-table-column prop="mobile" label="用户手机号码" width="140">
                </el-table-column>
                <el-table-column label="【项目|门店|商品】名称" width="200">
                    <template slot-scope="scope">
                        <div v-show="value==2">{{scope.row.item_name}}</div>
                        <div v-show="value==3">{{scope.row.goods_name}}</div>
                        <div v-show="value==1">{{scope.row.store_name}}</div>
                        
                    </template>
                </el-table-column>
                <el-table-column  label="评价内容" >
                    <template slot-scope="scope">
                        <div v-show="value==2">{{scope.row.item_comment}}</div>
                        <div v-show="value==3">{{scope.row.comment}}</div>
                        <div v-show="value==1">{{scope.row.store_comment}}</div>
                    </template>
                </el-table-column>
                <el-table-column type="expand" label="查看详细评价" width="120" align="center">
                    <template slot-scope="scope">
                        <div class="bs-callout bs-callout-danger">
                            <span v-show="value==2">项目名称：{{scope.row.item_name}}</span>
                            <span v-show="value==3">商品名称：{{scope.row.goods_name}}</span>
                            <span v-show="value==1">门店名称：{{scope.row.store_name}}</span>
                            <span style="padding-left:30px;">用户昵称：{{scope.row.nick_name}}</span>
                            <span style="padding-left:30px;">用户手机号码：{{scope.row.mobile}}</span>
                            <div style="height:30px;"></div>
                            <div>
                                评价内容：
                                <span v-show="value==2">{{scope.row.item_name}}</span>
                                <span v-show="value==3">{{scope.row.goods_name}}</span>
                                <span v-show="value==1">{{scope.row.store_name}}</span>
                            </div>
                            <div style="height:30px;"></div>
                            <div>
                                评价图片：
                                <div v-if="value==1"  v-for="item in scope.row.store_img" :key="item" style="display:inline-block;margin-right:20px;margin-bottom :20px;">
                                    <img :src="item" style="width:100px;height:100px;"/>
                                </div>
                                <div v-if="value==2"  v-for="item in scope.row.item_img" :key="item" style="display:inline-block;margin-right:20px;margin-bottom :20px;">
                                    <img :src="item" style="width:100px;height:100px;"/>
                                </div>
                                <div v-if="value==3"  v-for="item in scope.row.img" :key="item" style="display:inline-block;margin-right:20px;margin-bottom :20px;">
                                    <img :src="item"  style="width:100px;height:100px;"/>
                                </div>
                               
                            </div>
                        </div>
                        
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="140" align="center">
                    <template slot-scope="scope">
                        <el-button size="small" type="text" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" >
                <el-pagination @current-change="handleCurrentChange" layout="prev, pager, next" :total="totalPages">
                </el-pagination>
            </div>
        </div>
        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name:"appraise",
    data () {
        return {
            value:'2',
            options:[{
            value: '2',
            label: '项目'
            },{
            value: '1',
            label: '门店'
            },{
            value: '3',
            label: '商品'
            }],
            nickName:'',
            title:'',
            mobile:'',
            pageIndex:1,//当前页码
            pageSize:10,//每页10条
            totalPages:1,//默认的总条数
            tableData:[],//表格数据
            delVisible:false, //是否显示查看详情弹出层
            delIndex:0,
            delId:0

        }
    },
    created() {
            this.getMemberData();
    },
    methods: {
        //获取tabs数据
        getMemberData (){
            var _this = this;
            const querystring = require('querystring');
            const param ={
                type:this.value,
                nickName:this.nickName,
                mobile:this.mobile,
                title:this.title,
                pageIndex:this.pageIndex,
                pageSize:this.pageSize
            }
            
            this.$axios.get('/manage/evaluate/list',{ params:param}).then(response=>{
                // console.log(response);
                if(response.data.code==200){
                    response.data.data.currData.forEach(element => {
                        
                        if(_this.value ==1){
                            var store_img = element.store_img;
                            if(JSON.parse(store_img)){
                                element.store_img = JSON.parse(store_img);
                            }
                        }else if(_this.value ==2){
                            
                            var item_img = element.item_img;
                            console.log(item_img);
                            if(JSON.parse(item_img)){
                                element.item_img = JSON.parse(item_img);
                            }else{
                                element.item_img = [];
                            }
                            
                        }else{
                            var img = element.img;
                            if(JSON.parse(img)){
                                element.img = JSON.parse(img);
                            }
                        }
                    });
                    console.log(response.data.data.currData);
                    this.tableData = response.data.data.currData;//赋值 table 列表数据
                    this.totalPages = response.data.data.totalElements;//更新分页总条数
                }else{
                    this.$notify.error({
                        title: '失败',
                        duration:2000,
                        message: '失败原因：'+response.data.msg
                    });
                }
                
            }).catch(error=>{
                console.log(error); 
            });
        },
        // 分页导航
        handleCurrentChange (val){
             this.pageIndex = val
                this.getMemberData()
        },
        //查询
        search (){
            this.getMemberData();
        },
        //编辑
        handleEdit (index,row){
            if(row.id && row.id>0){
                this.$router.push({path:"/news/add",query:{id:row.id}});
            }
        },
        //删除
        handleDelete (index,row){
            if(row.id && row.id>0){
                this.delVisible = true;
                this.delIndex = index;//当前要删除的下标
                this.delId = row.id;// 当前选中ID
            }
        },
        deleteRow (){
            //console.log("触发了确定");
            if(this.delId>0){
                const querystring = require('querystring');
                const param ={
                    type:this.value,
                    id:this.delId
                }
                this.$axios.post('/manage/evaluate/delete',querystring.stringify(param)).then(response=>{
                    //console.log(response);
                    if(response.data.code==200){
                        this.tableData.splice(this.delIndex, 1);
                        this.$message.success('删除成功');
                        this.delVisible = false;
                    }else{
                        this.$notify.error({
                            title: '删除失败',
                            duration:2000,
                            message: '失败原因：'+response.data.msg
                        });
                    }
                    
                }).catch(error=>{
                    console.log(error); 
                });
            }
        },
        //查询新闻详情，跳转到详情页面
        handleSelect (index, row){
            if(row.id && row.id>0){
                this.$router.push({path:"/news/select/"+row.id});
            }
            
        }  
            
    }
}
</script>
<style lang="stylus" scoped>
    .handle-box {
        margin-bottom: 20px;
        
        
        
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 160px;
        display: inline-block;
        margin-right :30px;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }

.bs-callout {
    padding: 20px;
    border: 1px solid #eee;
    border-left-width: 5px;
    border-radius: 3px;
}
    .bs-callout-danger {
    border-left-color: #ce4844;
}
</style>


